package com.atguigu.exam;

import java.util.ArrayList;
import java.util.Iterator;

/**
 * 创建一个List集合的对象，添加几条数据，
 将1号位和2号位交换；获得最大值，最小值打印出来，
 最后再遍历该集合并把元素打印出来
 * @author xbd
 * @create 2021-05-28 12:05
 */
public class AddTest {
    public static void main(String[] args) {
        ArrayList list = new ArrayList();

        list.add(10);
        list.add(20);
        list.add(30);
        list.add(25);
        list.add(35);
        list.add(40);
        System.out.println(list);

        System.out.println("List集合的第一位元素：" + list.get(1));
        System.out.println("List集合的第二位元素：" + list.get(2));

        int temp = (int)list.get(1);
        list.set(1, list.get(2));
        list.set(2, temp);
        System.out.println(list);

        int Max = (int) list.get(0);
        int Min = (int) list.get(0);
        for (int i = 0; i < list.size(); i++) {
            if (Max < (int) list.get(i)) {
                Max = (int) list.get(i);
            }
            if (Min > (int) list.get(i)) {
                Min = (int) list.get(i);
            }
        }
        System.out.println("最大值："+Max);
        System.out.println("最小值："+Min);

        Iterator it = list.iterator();
        while (it.hasNext()){
            System.out.println(it.next());
        }


    }
}
